{include file='common/head' /}
    <body>
        <div class="x-nav">
          <span class="layui-breadcrumb">
              <a><cite>系统管理</cite></a>
              <a><cite>管理员管理</cite></a>
          </span>
          <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
        </div>
        <div class="layui-fluid">
            <div class="layui-row layui-col-space15">
                <div class="layui-col-md12">
                    <div class="layui-card">
                        <div class="layui-card-body ">
                            <form class="layui-form layui-col-space5">
                                <div class="layui-inline layui-show-xs-block">
                                    <input type="text" name="account"  placeholder="管理员账号" autocomplete="off" class="layui-input" value="{$get.account|default=''}">
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <input type="text" name="name"  placeholder="管理员昵称" autocomplete="off" class="layui-input" value="{$get.name|default=''}">
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <input type="text" name="tel"  placeholder="管理员手机" autocomplete="off" class="layui-input" value="{$get.tel|default=''}">
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <select name="status">
                                        <option value="">状态筛选</option>
                                        {volist name="status" id="v"}
                                        <option value="{$key}" {if condition="$get['status'] == $key"}selected{/if}>{$v}</option>
                                        {/volist}
                                    </select>
                                </div>
                                <div class="layui-inline layui-show-xs-block">
<!--                                    lay-verify="required"-->
                                    <select name="role_id" >
                                        <option value="">角色筛选</option>
                                        {volist name="role" id="v"}
                                        <option value="{$key}" {if condition="$get['role_id'] == $key"}selected{/if}>{$v}</option>
                                        {/volist}
                                    </select>
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <select name="shop_id">
                                        <option value="">账号类型</option>
                                        <option value="0" {if condition="$get['shop_id'] == 0"}selected{/if}>后台账号</option>
                                        <option value="1" {if condition="$get['shop_id'] == 1"}selected{/if}>商家账号</option>
                                    </select>
                                </div>
                                <div class="layui-inline layui-show-xs-block">
                                    <button class="layui-btn"  lay-submit="" lay-filter="sreach"><i class="layui-icon">&#xe615;</i></button>
                                </div>
                            </form>
                        </div>
                        <div class="layui-card-header">
                            <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="iconfont">&#xe69d;</i> 批量删除</button>
                            <button class="layui-btn" onclick="xadmin.open('添加管理员','/admin/system/edit',600,400)"><i class="layui-icon"></i>管理员</button>
                            <span style="line-height:40px;float: right;">共有数据：{$count} 条</span>
                        </div>
                        <div class="layui-card-body layui-table-body layui-table-main">
                            <table class="layui-table layui-form">
                                <thead>
                                  <tr>
                                    <th style="text-align: center;width: 2%">
                                      <input type="checkbox" lay-filter="checkall" name="" lay-skin="primary">
                                    </th>
                                    <th style="text-align: center;width: 15%">登陆账号</th>
                                    <th style="text-align: center;width: 15%">管理员昵称</th>
                                    <th style="text-align: center;width: 15%">管理员手机</th>
                                    <th style="text-align: center;width: 6%">管理员角色</th>
                                    <th style="text-align: center;width: 6%">管理员状态</th>
                                      <th style="text-align: center;width: 6%">账号类型</th>
                                    <th style="text-align: center;width: 6%">添加时间</th>
                                    <th style="text-align: center;width: 35%">操作</th>
                                  </tr>
                                </thead>
                                <tbody>
                                {volist name="list" id="v"}
                                  <tr>
                                    <td style="text-align: center;">
                                      <input type="checkbox" name="id" value="{$v.id}"   lay-skin="primary">
                                    </td>
                                    <td style="text-align: center;">{$v.account}</td>
                                    <td style="text-align: center;">{$v.name}</td>
                                    <td style="text-align: center;">{$v.tel}</td>
                                    <td style="text-align: center;">{$role[$v['role_id']]}</td>
                                    <td style="text-align: center;" class="td-status">
                                        {if condition="$v['status'] eq 1"}
                                            <span class="layui-btn layui-btn-normal layui-btn-mini">已启用</span>
                                        {/if}
                                        {if condition="$v['status'] eq 2"}
                                        <span class="layui-btn layui-btn-danger layui-btn-mini">已冻结</span>
                                        {/if}
                                        {if condition="$v['status'] eq 3"}
                                        <span class="layui-btn layui-btn-danger layui-btn-mini">已禁用</span>
                                        {/if}
                                    </td>
                                      <td style="text-align: center;">
                                          {if $v.shop_id > 0}
                                            商家账号
                                            <hr>
                                            {if $v->getShopOne}
                                            <span onclick="copyCode('{$v->getShopOne->id}')">店铺序号：{$v->getShopOne['id']}</span>
                                            <hr>
                                            <span onclick="copyCode('{$v.getShopOne->name}')">店铺名称:{$v.getShopOne->name}</span>
                                            <img width="80px" src="{$v.getShopOne->logo}" alt="">
                                            {/if}
                                          {else/}
                                            后台账号
                                          {/if}
                                      </td>
                                    <td style="text-align: center;">{:date('Y-m-d H:i:s',$v['add_time'])}</td>
                                    <td style="text-align: center;" class="td-manage">
                                        {if condition="$v['status'] eq 2 or $v['status'] eq 3"}
                                          <button class="layui-btn layui-btn layui-btn-xs" onclick="member_start(this,{$v['id']})" href="javascript:;"  title="启用">
                                            <i class="iconfont">&#xe6b1;</i>启用
                                          </button>
                                        {else /}
                                        <button class="layui-btn-danger layui-btn layui-btn-xs" onclick="member_stop(this,{$v['id']})" href="javascript:;"  title="禁用">
                                            <i class="iconfont">&#xe6b7;</i>禁用
                                        </button>
                                        {/if}
                                      <button class="layui-btn layui-btn layui-btn-xs" title="编辑"  onclick="xadmin.open('编辑','/admin/system/edit?id={$v.id}',600,400)" href="javascript:;">
                                        <i class="layui-icon">&#xe642;</i>编辑
                                      </button>
                                      <button class="layui-btn-danger layui-btn layui-btn-xs" title="删除" onclick="member_del(this,{$v['id']})" href="javascript:;">
                                        <i class="layui-icon">&#xe640;</i>删除
                                      </button>
                                    </td>
                                  </tr>
                                {/volist}
                                </tbody>
                            </table>
                        </div>
                        <div class="layui-card-body ">
                            <div class="page">
                                {$page}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div> 
    </body>
    <script>
      layui.use(['laydate','form'], function(){
        var  form = layui.form;

        // 监听全选
        form.on('checkbox(checkall)', function(data){
          if(data.elem.checked){
            $('tbody input').prop('checked',true);
          }else{
            $('tbody input').prop('checked',false);
          }
          form.render('checkbox');
        });
      });

       /*用户-停用*/
      function member_stop(obj,id){
          layer.confirm('确认要禁用吗？',function(index){
              var ids = [];
              ids.push(id);
              $.ajax({
                  url:"{:url('System/admin_status')}",
                  type: "post",
                  data:{id:ids,'type':'stop'},
                  dataType:"json",
                  success:function (res) {
                      if(res.code == 200){
                          $(obj).attr('onclick','member_start(this,'+id+')');
                          $(obj).attr('title','启用');
                          $(obj).html('<i class="iconfont">&#xe6b1;</i>启用');
                          $(obj).removeClass('layui-btn-danger');
                          $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-normal').addClass('layui-btn-danger').html('已禁用');
                          layer.msg('禁用成功', {icon: 1,time:1000});
                      }else{
                          layer.alert(res.msg, {icon:2,time:1000});
                      }
                  },
                  error:function(e){
                      layer.alert("网络错误", {icon:5,time:1000});
                  },
              });
          });
      }

      /*用户-启用*/
      function member_start(obj,id){
          layer.confirm('确认要启用吗？',function(index){
              var ids = [];
              ids.push(id);
              $.ajax({
                  url:"{:url('System/admin_status')}",
                  type: "post",
                  data:{id:ids,'type':'start'},
                  dataType:"json",
                  success:function (res) {
                      if(res.code == 200){
                          $(obj).attr('onclick','member_stop(this,'+id+')');
                          $(obj).attr('title','禁用');
                          $(obj).html('<i class="iconfont">&#xe6b7;</i>禁用');
                          $(obj).addClass('layui-btn-danger');
                          $(obj).parents("tr").find(".td-status").find('span').removeClass('layui-btn-danger').addClass('layui-btn-normal').html('已启用');
                          layer.msg('启用成功', {icon: 1,time:1000});
                      }else{
                          layer.alert(res.msg, {icon:2,time:1000});
                      }
                  },
                  error:function(e){
                      layer.alert("网络错误", {icon:5,time:1000});
                  },
              });
          });
      }

      /*用户-删除*/
      function member_del(obj,id){
          layer.confirm('确认要删除吗？',function(index){
              var ids = [];
              ids.push(id);
              $.ajax({
                  url:"{:url('System/admin_status')}",
                  type: "post",
                  data:{id:ids,'type':'del'},
                  dataType:"json",
                  success:function (res) {
                      if(res.code == 200){
                          layer.msg('删除成功', {icon: 1,time:1000});
                          $(obj).parents("tr").remove();
                      }else{
                          layer.alert(res.msg, {icon:2,time:1000});
                      }
                  },
                  error:function(e){
                      layer.alert("网络错误", {icon:5,time:1000});
                  },
              });
          });
      }

      //批量删除
      function delAll (argument) {
        var ids = [];
        // 获取选中的id 
        $('tbody input').each(function(index, el) {
            if($(this).prop('checked')){
               ids.push($(this).val())
            }
        });
  
        layer.confirm('确认要删除吗？',function(index){
            $.ajax({
                url:"{:url('System/admin_status')}",
                type: "post",
                data:{id:ids,'type':'del'},
                dataType:"json",
                success:function (res) {
                    if(res.code == 200){
                        //捉到所有被选中的，发异步进行删除
                        layer.msg('删除成功', {icon: 1,time:1000});
                        $(".layui-form-checked").not('.header').parents('tr').remove();
                    }else{
                        layer.alert(res.msg, {icon:2,time:1000});
                    }
                },
                error:function(e){
                    layer.alert("网络错误", {icon:5,time:1000});
                },
            });
        });
      }
    </script>
{include file='common/scroll' /}
{include file='common/copyCode' /}
{include file='common/footer' /}